//
//  UIImageView+WebImage.swift
//  Weibo
//
//  Created by Albert Zhu on 16/10/19.
//  Copyright © 2016年 Albert Zhu. All rights reserved.
//

import SDWebImage

extension UIImageView {
    
    /// 隔离SDWebImage设置图像方法
    ///
    /// - parameter urlString:        URLString
    /// - parameter placeholderImage: 占位图片
    /// - parameter isAvatar:         是否是头像
    func az_setImage(urlString: String?, placeholderImage: UIImage?, isAvatar: Bool = false) {
        
        guard let urlString = urlString,
            let url = URL(string: urlString) else {
            image = placeholderImage
            return
        }
        
        sd_setImage(with: url, placeholderImage: placeholderImage, options: [], progress: nil) { (image, _, _, _) in
            // 完成回调，判断是否是头像
            if isAvatar {
                 self.image = image?.az_avatarImage(size: self.bounds.size)
            }
        }
    }
}
